<?php

class App_Util_AutoCompletar {
	
	private $autoComplete;
	function __construct($url, $cajatexto,$campohidden="") {
		 $baseUrl = Zend_Controller_Front::getInstance ()->getBaseUrl();
		
		if(empty($campohidden)){
			$campohidden="cod{$cajatexto}";
		}
		$this->autoComplete ["url"] = $baseUrl.$url;
		$this->autoComplete ["cajatexto"] = $cajatexto;
		$this->autoComplete ["campohidden"] = $campohidden;
	}
	
	function renderElement() {
		$HTMLauto="";
		$HTMLauto.="<script type=\"text/javascript\">
		$(document).ready(function() {
			$(\"#{$this->autoComplete ["cajatexto"]}\").autocomplete('{$this->autoComplete ["url"]}');
			$(\"#{$this->autoComplete ["cajatexto"]}\").result(function(event, data, formatted) {
				var campoHidden = document.getElementById(\"{$this->autoComplete ["campohidden"]}\");
				campoHidden.value=data[1];
	});
			});
	</script>
	";
		return $HTMLauto;
	}
}

?>